import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

import '../../model/historyConversionsModel.dart';

class HistoryItem extends StatelessWidget {
  HistoryItem(this.item, {required this.onDelete,this.onTap, Key? key}) : super(key: key);
  HistoryConversionItem item;
  VoidCallback? onTap;
  Function(HistoryConversionItem) onDelete;
  @override
  Widget build(BuildContext context) {
    return Slidable(
        key: Key(item.id ?? ''),
        endActionPane: ActionPane(
          motion: ScrollMotion(),
          children: [
            SlidableAction(
              backgroundColor: Colors.red,
              foregroundColor: Colors.white,
              icon: Icons.delete,
              label: 'Delete',
              onPressed: (BuildContext context) {
                onDelete(item);
              },
            ),
          ],
        ),
        child: InkWell(
          onTap: onTap,
          child: Container(
            margin: const EdgeInsets.only(bottom: 15),
            padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
            decoration: BoxDecoration(
              color: const Color(0x80eeeeee),
              borderRadius: BorderRadius.circular(5),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  children: [
                    Expanded(
                      child: Text(
                        item.name ?? '',
                        style: const TextStyle(
                          color: Colors.black,
                          fontWeight: FontWeight.w600,
                          fontSize: 14,
                        ),
                      ),
                    ),
                    // SizedBox(width: 5),
                    // Icon(Icons.file_copy_outlined,size: 30,),
                  ],
                ),
                const SizedBox(height: 10),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    const Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(
                          '浮生AI',
                          style: TextStyle(
                            fontSize: 10,
                            color: Color(0xff999999),
                          ),
                        ),
                        // const SizedBox(width: 5),
                        // Container(
                        //   padding: const EdgeInsets.all(3),
                        //   decoration: const BoxDecoration(
                        //     color: Color(0x80dddddd),
                        //   ),
                        //   alignment: Alignment.center,
                        //   child: const Text(
                        //     'GLM-4',
                        //     style: TextStyle(
                        //       fontSize: 8,
                        //       fontWeight: FontWeight.w600,
                        //       color: Color(0xff888888),
                        //     ),
                        //   ),
                        // ),
                      ],
                    ),
                    Flexible(
                      child: Text(
                        DateTime.fromMillisecondsSinceEpoch(
                                (item.created_at ?? 0) * 1000)
                            .toString(),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: const TextStyle(
                          color: Color(0xffcccccc),
                          fontSize: 10,
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        ));
  }
}
